package com.tuling.code.juc.collection.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class BolckQueueExample {
	public static void main(String[] args) {
		BlockingQueue<String> queue = new ArrayBlockingQueue<>(3);
		queue.add("a");
		queue.add("b");
		queue.offer("c");
		//queue.add("d"); //超出了大小，会抛出异常
		System.out.println(queue.offer("d")); //超出队列大小，返回false
		try {
			boolean f = queue.offer("d", 10, TimeUnit.SECONDS);
			System.out.println(f);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(queue.peek());//获取对头元素，但是不会删除元素
		System.out.println(queue.size());
		System.out.println(queue.poll());
		System.out.println(queue.size());//会出列
	}
}
